package com.cn.wxwinnie.java.mythread.fourthreadWithOneFunction;

/**
 * @author 潇湘暮雨 E-mail:wxwinnie@hotmail.com
 * 
 * @version 创建时间：2014年3月23日 上午8:17:37
 * 
 */
public class TargetObjectWithOneFunction {

	private int n = 8;

	private int getN() {
		return n;
	}

	private void setN(int nn) {
		this.n = nn;
	}

	private final static TargetObjectWithOneFunction to = new TargetObjectWithOneFunction();

	private TargetObjectWithOneFunction() {
	}

	public static TargetObjectWithOneFunction getInstance() {
		return to;
	}

	public synchronized int option(String cmd) {//放置到一个方法中来
		if (cmd.equals("add")) {
			int n = getN();
			setN(++n);
			System.out.println("inc:" + n);
			return n;
		} else {
			int n = getN();
			setN(--n);
			System.out.println("sub:" + n);
			return n;
		}
	}
}
